<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>UI框架 - 编辑器</title>

    <link href="../theme/todc-bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="../theme/todc-bootstrap/css/todc-bootstrap.min.css" rel="stylesheet">

    <link href="../theme/iconfont/iconfont.css" rel="stylesheet">
    <link href="../theme/css/mp-style.css" rel="stylesheet">
    <link href="../theme/css/mp-style-panel.css" rel="stylesheet">

    <!--[if lt IE 9]>
    <script src="../theme/todc-bootstrap/js/html5shiv.min.js"></script>
    <script src="../theme/todc-bootstrap/js/respond.min.js"></script>
    <![endif]-->

    <style>
        .mp-body{
            min-height: initial;
        }
        .mp-panel{
            padding-left: 0px;
            padding-right: 0px;
            padding-top: 15px;
        }
        .mp-padding-break{
            padding: 0px;
        }
        .mp-spy-body{
            padding-top: 1px;
        }
    </style>

</head>
<body>

<div class="mp-head">
    <div class="mp-wrapper">
        <div class="container-fluid">
            <div class="row">
                <div class="col-md-6">
                    <h1 class="mp-head-logo"><a href="/" title="微信公众平台"></a></h1>
                </div>
                <div class="col-md-6 mp-pull-right">
                    <ul class="mp-nav">
                        <li>
                            <div>
                                <a href="#" class="mp-head-message">
                                    <em class="mp-head-message-num">3</em>
                                </a>
                            </div>
                        </li>
                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
                                简体中文 <span class="caret"></span>
                            </a>
                            <ul class="dropdown-menu">
                                <li><a href="#">简体中文</a></li>
                                <li><a href="#">繁体中文</a></li>
                                <li><a href="#">日本語</a></li>
                                <li><a href="#">English</a></li>
                            </ul>
                        </li>
                        <li><a href="#">退出</a></li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="mp-body">
    <div class="mp-wrapper">

        <div style="width: 1200px; margin: auto;">
            <div class="mp-content">
                <div class="mp-spy-body"></div>
                <!-- 通知 -->
                <div class="mp-panel">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-md-2">
                                <div class="mp-spy-fixed">
                                    <button type="button" class="btn btn-block btn-default btn-lg">文章</button>
                                </div>
                            </div>
                            <div class="col-md-8 mp-padding-break">
                                <!-- 加载编辑器的容器 -->
                                <script id="container" name="content" type="text/plain">初始化内容</script>
                            </div>
                            <div class="col-md-2">
                                <div class="mp-spy-fixed">
                                    <button type="button" class="btn btn-block btn-default btn-lg">插入图片</button>
                                    <button type="button" class="btn btn-block btn-default btn-lg">插入视频</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="mp-foot">
    <div class="mp-wrapper">
        <div class="mp-content-wrapper">
            <div class="mp-content">
                <div class="mp-panel-foot">
                    <div class="container-fluid">
                        <div class="row line">
                            <div class="col-md-12 mp-group-link">
                                <a href="#" target="_blank">关于腾讯</a>
                                <a href="#" target="_blank">反馈官号</a>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-12">
                                Copyright © 2012-2018 Tencent. All Rights Reserved.
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

</body>
<script src="../theme/todc-bootstrap/js/jquery-1.12.4.min.js"></script>
<script src="../theme/todc-bootstrap/js/bootstrap.min.js"></script>
<script src="../theme/todc-bootstrap/plugins/jquery-scrollspy/scrollspy.js"></script>
<!-- 配置文件 -->
<script type="text/javascript" src="ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="ueditor/ueditor.all.js"></script>
<!-- 实例化编辑器 -->
<script type="text/javascript">

    UE.registerUI('insertimagebutton', function(editor, uiName) {
        //注册按钮执行时的command命令，使用命令默认就会带有回退操作
        editor.registerCommand(uiName, {
            execCommand: function() {
                alert('execCommand: ' + uiName)
            }
        });

        //创建一个button
        var btn = new UE.ui.Button({
            //按钮的名字
            name: uiName,
            //提示
            title: '插入图片素材',
            //需要添加的额外样式，指定icon图标，这里默认使用一个重复的icon
            cssRules : 'background-position:  -500px 0;',
            //点击时执行的命令
            onclick: function () {
                //这里可以不用执行命令, 做你自己的操作也可
                // editor.execCommand(uiName);
                // editor.execCommand( 'insertimage', {
                //     src: 'http://a.hiphotos.baidu.com/image/pic/item/fc1f4134970a304eb5088f73ddc8a786c9175c14.jpg',
                //     width: '100%',
                //     height: 'auto'
                // } );
                editor.execCommand( 'inserthtml', '<p><img src="http://a.hiphotos.baidu.com/image/pic/item/fc1f4134970a304eb5088f73ddc8a786c9175c14.jpg"></p>');
            }
        });

        //当点到编辑内容上时，按钮要做的状态反射
        editor.addListener('selectionchange',  function () {
            var state = editor.queryCommandState(uiName);
            if (state == -1) {
                btn.setDisabled(true);
                btn.setChecked(false);
            } else {
                btn.setDisabled(false);
                btn.setChecked(state);
            }
        });

        //因为你是添加button, 所以需要返回这个button
        return btn;
    }/*index 指定添加到工具栏上的那个位置，默认时追加到最后, editorId 指定这个UI是那个编辑器实例上的，默认是页面上所有的编辑器都会添加这个按钮*/);
    var ue = UE.getEditor('container', {
        toolbars: [
            ['fullscreen', 'source', 'undo', 'redo', 'bold', 'italic', 'underline', 'strikethrough'],
            ['imagenone', 'imageleft', 'imagecenter', 'imageright']
        ],
        autoHeightEnabled: true,
        autoFloatEnabled: true
    });

    $('.mp-spy-body').on('scrollSpy:enter', function() {
        $('.mp-spy-fixed').css({
            position: 'relative',
            top: '0px',
            width: '170px',
            'padding-top': '0px'
        });
    });

    $('.mp-spy-body').on('scrollSpy:exit', function() {
        $('.mp-spy-fixed').css({
            position: 'fixed',
            top: '0px',
            width: '170px',
            'padding-top': '15px'
        });
    });

    $('.mp-spy-body').scrollSpy();
</script>
</html>